#include "RegistryKey.h"

#include <iostream>
using namespace std;

void RegistryUtilsTest();

int main(int argc, char const *argv[])
{
    RegistryUtilsTest();

    return 0;
}

void RegistryUtilsTest()
{
    auto showChild = true;
    std::string regPath = R"(HKEY_CURRENT_USER\SOFTWARE\QtProject\QtCreator)";

    std::string testKey = "livio";
    RegistryKey regKey(regPath);

    // regKey.WriteSubKey(testKey, "livio_TEST"); // subkey不存在则创建

    std::string strValue;
    regKey.ReadSubKey(testKey, strValue);
    auto err = regKey.GetErrorCode();

    cout << "key: "
         << testKey << '\t'
         << "value: " << strValue << '\n';

    regKey.DeleteSubKey("livio");
    regKey.DeleteSubTree("livio");

    if (showChild)
    {
        std::vector<std::string> keys, groups;
        regKey.AllChildKeys(keys);
        regKey.AllChildGroups(groups);

        cout << "keys: \n";
        for (const auto &key : keys)
        {
            cout << '\t' << key << '\n';
        }
        cout << "groups: \n";
        for (const auto &group : groups)
        {
            cout << '\t' << group << '\n';
        }
    }
}